home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap18 / Emf9 / Emf9.c next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  1.3 KB  |  47 lines

  1. /*-------------------------------------
  2.    EMF9.C -- Enhanced Metafile Demo #9
  3.              (c) Charles Petzold, 1998
  4.   -------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include <string.h>
  8.  
  9. TCHAR szClass [] = TEXT ("EMF9") ;
  10. TCHAR szTitle [] = TEXT ("EMF9: Enhanced Metafile Demo #9") ;
  11.  
  12. void CreateRoutine (HWND hwnd)
  13. {
  14. }
  15.  
  16. void PaintRoutine (HWND hwnd, HDC hdc, int cxArea, int cyArea)
  17. {
  18.      ENHMETAHEADER emh ;
  19.      HENHMETAFILE  hemf ;
  20.      int           cxMms, cyMms, cxPix, cyPix, cxImage, cyImage ;
  21.      RECT          rect ;
  22.  
  23.      cxMms = GetDeviceCaps (hdc, HORZSIZE) ;
  24.      cyMms = GetDeviceCaps (hdc, VERTSIZE) ;
  25.      cxPix = GetDeviceCaps (hdc, HORZRES) ;
  26.      cyPix = GetDeviceCaps (hdc, VERTRES) ;
  27.  
  28.      hemf = GetEnhMetaFile (TEXT ("..\\emf8\\emf8.emf")) ;
  29.  
  30.      GetEnhMetaFileHeader (hemf, sizeof (emh), &emh) ;
  31.  
  32.      cxImage = emh.rclFrame.right - emh.rclFrame.left ;
  33.      cyImage = emh.rclFrame.bottom - emh.rclFrame.top ;
  34.  
  35.      cxImage = cxImage * cxPix / cxMms / 100 ;
  36.      cyImage = cyImage * cyPix / cyMms / 100 ;
  37.  
  38.      rect.left   = (cxArea - cxImage) / 2 ;
  39.      rect.right  = (cxArea + cxImage) / 2 ;
  40.      rect.top    = (cyArea - cyImage) / 2 ;
  41.      rect.bottom = (cyArea + cyImage) / 2 ;
  42.  
  43.      PlayEnhMetaFile (hdc, hemf, &rect) ;
  44.  
  45.      DeleteEnhMetaFile (hemf) ;
  46. }
  47.